package com.major.dawn.huawei;

public class DeleteNumber {


    public static int survivor(int[] nums) {
        int length = nums.length;
        int count = 0;
        for (int i = 0; i < length; i++) {
            nums[i] = 0;
        }
        int currentIndex = 0;
        while (length > 1) {
            while (count != 3) {
                currentIndex++;
                if (nums[currentIndex] == 0) {
                    count++;
                }
                currentIndex++;

            }
            nums[currentIndex] = 1;
            currentIndex++;
            count = 0;
            length--;
        }

        return currentIndex;
    }

    public static void main(String[] args) {

        int survivor = survivor(new int[]{1, 2, 3, 4, 5, 6, 7});
        System.out.println(survivor);

    }

    public int lastRemaining(int n, int m) {
        int ans = 0;
        // 最后一轮剩下2个人，所以从2开始反推
        for (int i = 2; i <= n; i++) {
            ans = (ans + m) % i;
        }
        return ans;
    }



}
